﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using BaseData.Common;
using BaseData.UI;
using TaxData.Tax;
using TaxEntity.User;
using TaxEntity.Tax;

namespace TaxBiz.Tax
{
    /// <summary>
    /// 完税逻辑层
    /// </summary>
    public class TaxCompleteBiz
    {
        private TaxCompleteData tcd = new TaxCompleteData();

        /// <summary>
        /// 获取完税信息实体(带缓存)
        /// </summary>
        public TaxCompleteEntity GetEntityById(long id)
        {
            TaxCompleteEntity  model = tcd.GetEntityById(id);
            return model;
        }

        /// <summary>
        /// 增加完税
        /// </summary>
        /// <param name="model">完税信息实体</param>
        /// <param name="optUser">操作人</param>
        /// <returns>成功完税编号,失败返回0</returns>
        public long Add(TaxCompleteEntity model, UserEntity optUser)
        {
            long id = tcd.Add(model);
            return id;
        }

        /// <summary>
        /// 修改完税信息
        /// </summary>
        /// <param name="model">修改完税</param>
        /// <param name="optUser">操作人</param>
        /// <returns>操作结果</returns>
        public bool Update(TaxCompleteEntity model, UserEntity optUser)
        {
            bool isSucc = tcd.Update(model);
            return isSucc;
        }

        /// <summary>
        /// 删除完税
        /// </summary>
        public bool Delete(long id, UserEntity optUser)
        {
            bool isSucc = tcd.Delete(id);
            return isSucc;
        }

        /// <summary>
        /// 获取完税列表
        /// </summary>
        public DataTable GetList(string strWhere, int pageSize, int page, ref int allCount)
        {
            DataTable dt = tcd.GetList(strWhere, pageSize, page, ref allCount);
            if (dt != null)
            {
                dt.Columns.Add("CompleteTax");
                TaxBiz.SysConfig.TaxsBiz tb = new SysConfig.TaxsBiz();
                foreach (DataRow dr in dt.Rows)
                {
                    Dictionary<string, decimal> requireTaxDic = new Dictionary<string, decimal>();
                    Dictionary<string, decimal> completeTaxDic = new Dictionary<string, decimal>();
                    tb.GetTaxDescDic(dr, out completeTaxDic, out requireTaxDic);

                    foreach (KeyValuePair<string, decimal> pair in completeTaxDic)
                    {
                        dr["CompleteTax"] += pair.Key + ":" + pair.Value.ToString() + "<br/>";
                    }
                }
            }
            return dt;
        }

        /// <summary>
        /// 获取完税列表
        /// </summary>
        public DataTable GetList(string certificateID)
        {
            DataTable dt = tcd.GetList(certificateID);
            return dt;
        }
    }
}
